/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.iFrames.HetmapFrameComponents;

import java.awt.Component;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

/**
 * 
 * @author bunkowski
 */
public class HeatmapPopUpModifier {

	// modifying the automatic popupmenu from jfreechart carefully by text to retain existing action listeners
	public static void modify(JPopupMenu popup) {

		// delete and rename existing menus
		for (int i = 0; i < popup.getComponents().length; i++) {
			Component c = popup.getComponent(i);
			if (c instanceof JMenuItem) {
				JMenuItem jMenu = (JMenuItem) c;
				String text = jMenu.getText();
				if ((text.equals("Zoom In") || text.equals("Zoom Out")) || text.equals("Auto Range")) {
					popup.remove(jMenu);
					i--;
				}
				if (text.equals("Properties...")) {
					jMenu.setText("Heatmap plot properties");
				}
				if (text.equals("Copy")) {
					jMenu.setText("Copy heatmap image");
				}
				if (text.equals("Save as...")) {
					jMenu.setText("Save heatmap image");
				}
				if (text.equals("Print...")) {
					jMenu.setText("Print heatmap image");
				}
			}

		}
		// add new menus

		// commented because only works if heatmap has been reloaded manually by the options button

		// JMenuItem jmi1 = new JMenuItem("Show compensation spectrum");
		// jmi1.addActionListener(new ActionListener() {
		// public void actionPerformed(ActionEvent e) {
		// if (ImageMethods.compensationSpectra != null) {
		// Vector<Double> data = new Vector<Double>();
		// for (int i = 0; i < ImageMethods.compensationSpectra.length; i++) {
		// double d = ImageMethods.compensationSpectra[i];
		// data.add(d);
		// }
		// ChartInternalFrame cif = new ChartInternalFrame();
		// cif.setData("", data, null, null);
		// cif.showLegend = false;
		// cif.showAsLineChart();
		// BaseFrame.applyFrame(cif);
		// cif.setBounds(20, 20, 600, 400);
		// System.out.println("piff");
		// } else {
		// System.out.println("poff");
		// }
		// }
		// });
		// popup.add(jmi1);
	}
}
